package com.itheima.web;

import com.itheima.pojo.Brand;
import com.itheima.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectAllServlet")
public class SelectAllServlet extends HttpServlet {

    private BrandService service = new BrandService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1.调用service查询
        //BrandService service = new BrandService();合理复用 提至成员
        List<Brand> brands = service.selectAll();
        //2.将查询结果存入到request
        request.setAttribute("brands", brands);//前一个brands是别名，后一个是对应的集合brands对象
        //3.将请求转发到brand.jsp
        request.getRequestDispatcher("/brand.jsp").forward(request,response);
        //response.sendRedirect("/brand-demo/brand.jsp");  这个地方不能用重定向
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}